#ifndef LEAMLOMSTREAMHH
#define LEAMLOMSTREAMHH
#include "stdincludes.hh"
#include "typedefs.hh"
#include "binary-in-stream.hh"
#include "binary-out-stream.hh"
#include "leam-handler.hh"
#include "lom-binary-out-stream.hh"
#include "lom-binary-in-stream.hh"
#include "lom-typedefs.hh"
#include "lom-transaction-system.hh"
#include "lom-stream-handle-map.hh"
#include "lom-instance.hh"
#include "lom-class.hh"

namespace leam
{
    class LeamStream;
}
    
namespace lom
{
    class ILomContext;
}

namespace leam_lom
{

    
    class LeamLomStream : public lom::ILomTransactionHandler
			  , public leam::ILeamHandler
			  , public lom::ILomIncomingHandleMap
    {
	//Map stream handles to world handles
	lom::THandleHandleMap streamWorldMap;
	lom::ILomContext* context;
	lom::LomBinaryInStream inStream;
	lom::LomBinaryOutStream outStream;
	lom::LomIdentityOutgoingHandleMap outgoingMap;
	
	licada::TDataVector dataVector;
	licada::VectorBinaryOutStream binOut;
	
	leam::LeamStream* leamStream;

	lom::TValueVector tempVector;
	licada::TNameStr tempStr;
	lom::LomInstance tempInstance;
	lom::LomClass tempClass;
	
    public:
	/**================================
	   Public API
	*/
	LeamLomStream();
	void setup( lom::ILomContext* context
		    , leam::LeamStream* leamStream );
	void reset();
	virtual void synchronizeClasses();
	virtual void synchronizedInstances();
	virtual void flush();

	
	/**===========================
	   ILomTransactionHandler Implementation.
	*/
	virtual void beginTransactionEvents();
	virtual void handle( const lom::ILomTransactionEvent* evt );
	virtual void endTransactionEvents();

	/**=================================
	   Incoming handle map implementation
	 */
	virtual lom::THandle streamToWorld( lom::THandle streamHandle );

	/**================================
	   LeamHandler implementation
	 */
	virtual void handleData( leam::TMessageId msg
				 , leam::LeamDataInStream& data );
	virtual void handleError( leam::TMessageId msg
				  , const std::string& stackTrace
				  , leam::LeamDataInStream& data );
	virtual void handleAck( leam::TMessageId msg );
	virtual void handleFin( leam::TMessageId msg );
	virtual void handleClose();
    };
}

#endif
